Passed
Push — master ( de752f...295ecd )
by
unknown
11:00
created

UnknownFilePlugin.js ➔ UnknownFilePlugin   F

Complexity

Conditions 17

Size

Total Lines 80
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 17
eloc 50
c 0
b 0
f 0
dl 0
loc 80
rs 1.8

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like UnknownFilePlugin.js ➔ UnknownFilePlugin often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
/**
2
 * Unknown File Plugin
3
 * @author grommunio GmbH <[email protected]>
4
 */
5
function UnknownFilePlugin() {
6
    "use strict";
7
8
    var divElement = undefined,
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as divElement is implicitly marked as undefined by the declaration.
Loading history...
9
        self       = this;
10
11
    function initCSS() {
12
    }
13
14
    function initButtons() {
15
        var leftToolbar                                          = document.getElementById('toolbarLeft');
16
        // hide unused elements
17
        document.getElementById("navButtons").style.display      = 'none';
18
        document.getElementById("pageNumberLabel").style.display = 'none';
19
        document.getElementById("pageNumber").style.display      = 'none';
20
        document.getElementById("numPages").style.display        = 'none';
21
        document.getElementById("toolbar").style.display         = 'none';
22
        document.getElementById("titlebarRight").style.display   = 'none';
23
        leftToolbar.style.visibility                             = "visible";
24
25
    }
26
27
    this.initialize = function ( viewerElement, documentUrl ) {
28
        divElement = document.createElement("div");
29
        divElement.setAttribute('class', 'unknown-file');
30
        divElement.innerHTML = 'This file cannot be previewed using your browser. <br><br><a class="download-button" href="' + documentUrl + '">Click here to download</a>';
31
32
        viewerElement.appendChild(divElement);
33
        viewerElement.style.overflow = "auto";
34
35
        self.onLoad();
36
37
        initCSS();
38
        initButtons();
39
    };
40
41
    this.isSlideshow = function () {
42
        return false;
43
    };
44
45
    this.onLoad = function () {
46
    };
47
48
    this.fitToWidth = function ( width ) {
49
    };
50
51
    this.fitToHeight = function ( height ) {
52
    };
53
54
    this.fitToPage = function ( width, height ) {
55
    };
56
57
    this.fitSmart = function ( width ) {
58
    };
59
60
    this.getZoomLevel = function () {
61
    };
62
63
    this.setZoomLevel = function ( value ) {
64
    };
65
66
    this.getPages = function () {
67
        return [1];
68
    };
69
70
    this.showPage = function ( n ) {
71
    };
72
73
    this.getPluginName = function () {
74
        return "UnknownFilePlugin";
75
    };
76
77
    this.getPluginVersion = function () {
78
        return "From Source";
79
    };
80
81
    this.getPluginURL = function () {
82
        return "https://grommunio.com";
83
    };
84
}
85